<?php 
class Administrator{
   
   /**
    * Array permission
   */
   public $arr_pms = array();
   
   /**
    * 
    * The id, username and password
   */
   public $id,$username,$password,$type;
   
   /**
    * 
    * The constructor
   */
   public function __construct($u,$p){
      $this->username = $u;
      $this->password = $p;
      $this->check_login();
   }
   public function check_login(){
      $username	= replaceMQ($this->username);
   	$password	= replaceMQ($this->password);
      
   	$db_check	= new db_query("SELECT 
                                       adt_id,adt_type 
   										 FROM 
                                       administrator
   										 WHERE 
                                       adt_username = '" . $username . "' 
                                  AND 
                                       adt_password = '" . md5($password) . "' 
                                  AND 
                                       adt_status = 1");
      if(mysql_num_rows($db_check->result) > 0){
   		$check	 = mysql_fetch_array($db_check->result);
   		$this->id    = $check['adt_id'];
         $this->type  = $check['adt_type'];
   		$db_check->close();
   		unset($db_check);
   		return $this->id;
   	}
   	else{
   		$db_check->close();
   		unset($db_check);
   		return 0;
   	}
   }
   
   public function getPermission(){
      if($this->type == 1){
         $string_query = "SELECT  
                              mod_name,
                              mod_file,
                              mod_dir,
                              mod_sub 
                           FROM 
                              modules 
                           WHERE 
                              mod_active = 1 
                           ORDER BY 
                              mod_order";
      }else{
         $string_query = "SELECT 
                              mod_name,
                              mod_file,
                              mod_dir,
                              mod_sub  
                           FROM 
                              modules
                           INNER JOIN  
                              author
                           ON
                              modules.mod_id = author.mod_id
                           WHERE 
                              mod_active = 1
                              AND
                              adt_id = ".$this->id." 
                           ORDER BY 
                              mod_order";
         $db_query = new db_query($string_query);
         $this->arr_pms = $db_query->resultArray();
         unset($db_query);
      }
   }
   
   
   
}
?>